package com.complex.spring.advance.service.annotation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

/**
 * 注解注入的使用
 * @author gao
 *
 */
@Component
public class TestAnnotation {
	@Autowired
	private TestAnnotationA annotationA;
	public void getAnnotationA(){
		if(annotationA != null){
			System.out.println("annotationA not null");
		}else{
			System.out.println("annotationA is null");
		}
	}
	public static void main(String[] args) {
		//注意XML的schema
		ApplicationContext context = new ClassPathXmlApplicationContext("/bean/spring-annotation.xml");
		//bean默认的名字是类名首字母小写
		TestAnnotation an = (TestAnnotation)context.getBean("testAnnotation");
		an.getAnnotationA();
	}
}
